/*
 * Tri.java
 *
 * Created on 13 luty 2008, 11:47
 *
 * Klasa reprezentuje JEDEN trojkat !!!
 */
  
package tri;

import java.awt.Color;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

/**
 * Klasa opisujaca trojkat
 * @author arkadiusz
 */

public class Tri {
   Vector3d vab;
   Vector3d vbc;
   Vector3d vca;
   Point3d a;
   Point3d b;
   Point3d c;
   
   public Tri() {
   }
   public Tri(Point3d a, Point3d b, Point3d c) {
      this.a = a;
      this.b = b;
      this.c = c;
      this.vab = new Vector3d(a.x - b.x, a.y - b.y, a.z - b.z);
      this.vbc = new Vector3d(b.x - c.x, b.y - c.y, b.z - c.z);
      this.vca = new Vector3d(c.x - a.x, c.y - a.x, c.z - a.z);
   }
   
   Point3d[] getPoints3d(){
      return new Point3d[]{this.a, this.b, this.c};
   }
   Vector3d getNormalny(){
      Vector3d vr = new Vector3d();
      vr.cross(this.vab , this.vbc);
      return vr;
   }
   Color getColor(){
     Vector3d v = this.getNormalny();
     v.normalize();
    
     //System.out.println("v:"+v);
     int r = (int)(255*Math.abs(v.x));
     int g = (int)(255*Math.abs(v.y));
     int b = (int)(255*Math.abs(v.z));
     //System.out.println(r+","+g+","+b);
     return new Color(r,g,b);
   }
}
